{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "827b922d",
   "metadata": {},
   "source": [
    "Python内置了很多函数，可以直接调用。需要知道函数的名称和参数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0e3fd508",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "082c5dc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(-20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1239626b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "23f1f19e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(2,3,1,-5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77615b0b",
   "metadata": {},
   "source": [
    "### 数据类型转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1e701aff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "123"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int('123')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "93677fc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(12.13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0e5c42a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.34"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "float('12.34')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d3a8fdcd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.23'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(1.23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ffb62958",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8da1ec16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "eb627ed9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool('')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c0c3030c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool('a')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68cba634",
   "metadata": {},
   "source": [
    "函数名其实就是指向一个函数对象的引用，完全可以把函数名赋给一个变量，相当于给这个函数起了一个别名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c442025c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = abs\n",
    "a(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b94e84ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0xff\n",
      "0x3\n"
     ]
    }
   ],
   "source": [
    "n1 = 255\n",
    "n2 = 3\n",
    "print(hex(n1))\n",
    "print(hex(n2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8d631e3",
   "metadata": {},
   "source": [
    "### 小结"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a23b7656",
   "metadata": {},
   "source": [
    "调用Python函数，需根据函数定义传入正确参数，如果出错，注意看错误信息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40850ac1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
